Skip to content

Reject linked dylib EII default overrides#156370

Open
qaijuang wants to merge 6 commits into
rust-lang:mainfrom
qaijuang:eii-dylib-default-override
Open

Reject linked dylib EII default overrides#156370
qaijuang wants to merge 6 commits into
rust-lang:mainfrom
qaijuang:eii-dylib-default-override

Conversation

@qaijuang

@qaijuang qaijuang commented May 9, 2026

Copy link
Copy Markdown
Contributor

View all comments

This PR rejects explicit EII implementations that would override a default implementation already selected through a linked dylib.

The check is intentionally split:

  • rustc_passes keeps the early, format-independent checks for missing impls and duplicate explicit impls.
  • rustc_codegen_ssa checks the default-vs-explicit conflict during linking, using the dependency formats selected for the final artifact.

Fixes #156320.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 9, 2026
@qaijuang qaijuang marked this pull request as ready for review May 9, 2026 20:28
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 9, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 9, 2026
@rustbot

rustbot commented May 9, 2026

Copy link
Copy Markdown
Collaborator

r? @mejrs

rustbot has assigned @mejrs.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 19 candidates

@qaijuang

qaijuang commented May 9, 2026

Copy link
Copy Markdown
Contributor Author

cc @bjorn3

@mejrs

mejrs commented May 9, 2026

Copy link
Copy Markdown
Contributor

r? @jdonszelmann (or @bjorn3 perhaps)

@rustbot rustbot assigned jdonszelmann and unassigned mejrs May 9, 2026
@rustbot

rustbot commented May 9, 2026

Copy link
Copy Markdown
Collaborator

jdonszelmann is currently at their maximum review capacity.
They may take a while to respond.

@bjorn3

bjorn3 commented May 10, 2026

Copy link
Copy Markdown
Member

Thinking about this a bit more, I'm wondering if maybe check_externally_implementable_items should be done only at link time? tcx.used_crate_source() may report that only a dylib exists even when at link time an rlib will be available and linked in. And tcx.dependency_formats() will report everything as NotLinked inside rlibs and would ideally only be called during the link step for -Zno-link/-Zlink-only to work (it is currently broken because dependency_formats is called during codegen. i've been working on moving this call to the link step for the past several months). On the other hand for all cases that the check caught before this PR, doing it before linking is fine. So splitting it into separate checks for duplicate explicit impls and for a default impl conflicting with an explicit impl would preserve early error messages (especially for cargo check) What do you think @jdonszelmann?

@qaijuang

Copy link
Copy Markdown
Contributor Author

Thinking about this a bit more, I'm wondering if maybe check_externally_implementable_items should be done only at link time? tcx.used_crate_source() may report that only a dylib exists even when at link time an rlib will be available and linked in. And tcx.dependency_formats() will report everything as NotLinked inside rlibs and would ideally only be called during the link step for -Zno-link/-Zlink-only to work (it is currently broken because dependency_formats is called during codegen.

Nice catch @bjorn3

So splitting it into separate checks for duplicate explicit impls and for a default impl conflicting with an explicit impl would preserve early error messages (especially for cargo check)

right? seems like the next best move

@qaijuang qaijuang force-pushed the eii-dylib-default-override branch from dfc410a to 44e8bb8 Compare May 11, 2026 15:11
@qaijuang qaijuang changed the title Reject EII overrides of dylib defaults Reject linked dylib EII default overrides May 11, 2026
@qaijuang

Copy link
Copy Markdown
Contributor Author

@bjorn3 I'm done with the split, what do you think?

@rust-bors

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 14, 2026
@qaijuang qaijuang force-pushed the eii-dylib-default-override branch from 5af5be7 to b41cef3 Compare May 14, 2026 20:14
@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 14, 2026
@jdonszelmann

Copy link
Copy Markdown
Contributor

@bjorn3 that approach seems reasonable to me

Comment thread compiler/rustc_codegen_ssa/src/back/link.rs Outdated
Comment thread compiler/rustc_codegen_ssa/src/base.rs Outdated
@qaijuang qaijuang force-pushed the eii-dylib-default-override branch from 3827ccb to 621745e Compare May 28, 2026 17:36
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 8, 2026
@rustbot

rustbot commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@qaijuang

qaijuang commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 8, 2026
@rust-log-analyzer

This comment has been minimized.

@qaijuang qaijuang force-pushed the eii-dylib-default-override branch from 48d4bf3 to 3378897 Compare July 8, 2026 12:20

@bjorn3 bjorn3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me with the below changes.

View changes since this review

Comment thread compiler/rustc_codegen_ssa/src/base.rs Outdated
Comment thread compiler/rustc_codegen_ssa/src/base.rs Outdated
@bjorn3 bjorn3 assigned bjorn3 and unassigned jdonszelmann Jul 8, 2026
@bjorn3 bjorn3 added the F-extern_item_impls `#![feature(extern_item_impls)]` label Jul 8, 2026
@bjorn3

bjorn3 commented Jul 8, 2026

Copy link
Copy Markdown
Member

Thanks!

@bors r+

@rust-bors

rust-bors Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 41bdaed has been approved by bjorn3

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 8, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 8, 2026
…e, r=bjorn3

Reject linked dylib EII default overrides

This PR rejects explicit EII implementations that would override a default implementation already selected through a linked dylib.

The check is intentionally split:
- rustc_passes keeps the early, format-independent checks for missing impls and duplicate explicit impls.
- rustc_codegen_ssa checks the default-vs-explicit conflict during linking, using the dependency formats selected for the final artifact.

Fixes rust-lang#156320.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 8, 2026
…e, r=bjorn3

Reject linked dylib EII default overrides

This PR rejects explicit EII implementations that would override a default implementation already selected through a linked dylib.

The check is intentionally split:
- rustc_passes keeps the early, format-independent checks for missing impls and duplicate explicit impls.
- rustc_codegen_ssa checks the default-vs-explicit conflict during linking, using the dependency formats selected for the final artifact.

Fixes rust-lang#156320.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 8, 2026
…e, r=bjorn3

Reject linked dylib EII default overrides

This PR rejects explicit EII implementations that would override a default implementation already selected through a linked dylib.

The check is intentionally split:
- rustc_passes keeps the early, format-independent checks for missing impls and duplicate explicit impls.
- rustc_codegen_ssa checks the default-vs-explicit conflict during linking, using the dependency formats selected for the final artifact.

Fixes rust-lang#156320.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 8, 2026
…e, r=bjorn3

Reject linked dylib EII default overrides

This PR rejects explicit EII implementations that would override a default implementation already selected through a linked dylib.

The check is intentionally split:
- rustc_passes keeps the early, format-independent checks for missing impls and duplicate explicit impls.
- rustc_codegen_ssa checks the default-vs-explicit conflict during linking, using the dependency formats selected for the final artifact.

Fixes rust-lang#156320.
rust-bors Bot pushed a commit that referenced this pull request Jul 8, 2026
…uwer

Rollup of 25 pull requests

Successful merges:

 - #158871 (add relnotes for 1.97.0)
 - #158968 (stdarch subtree update)
 - #154445 (rustdoc: Represent `--output-format=json` coverage and ir differently)
 - #156370 (Reject linked dylib EII default overrides)
 - #157153 (allow `Allocator`s to be used as `#[global_allocator]`s)
 - #158495 (Rename HAS_CT_PROJECTION to HAS_CONST_ALIAS)
 - #158617 (allow mGCA const arguments to fall back to anon consts)
 - #158645 (Fix splat ICEs and ban it in closures)
 - #158655 (Fix coroutine MIR saved local remapping)
 - #158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`)
 - #158912 (Introduce new bootstrap config section for PGO configuration)
 - #158920 (Update wasm-component-ld to 0.5.26)
 - #158926 (wrapping_sh* methods: clarify underspecified reference)
 - #158927 (add core test run with `-Zforce-intrinsic-fallback`)
 - #158932 (Do not build the compiler when invoking `x perf compare`)
 - #158937 (Emit the emscripten entry point as `__main_argc_argv`)
 - #151379 (Stabilize `VecDeque::retain_back` from `truncate_front`)
 - #156548 ( Library support for aarch64-unknown-linux-pauthtest target)
 - #158307 (CI job for parallel frontend ui tests)
 - #158347 (Improve generic parameters handling for #[diagnostic::on_const])
 - #158722 (delegation: do not always inherit `ConstArgHasType` predicates)
 - #158741 (Simplify `Option::into_flat_iter` signature)
 - #158807 (Add regression test for CString::clone_into unwind safety)
 - #158862 (Fix the span for parameter suggestion )
 - #158883 (tests: fix enum-match.rs to handle LLVM 23)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 8, 2026
…e, r=bjorn3

Reject linked dylib EII default overrides

This PR rejects explicit EII implementations that would override a default implementation already selected through a linked dylib.

The check is intentionally split:
- rustc_passes keeps the early, format-independent checks for missing impls and duplicate explicit impls.
- rustc_codegen_ssa checks the default-vs-explicit conflict during linking, using the dependency formats selected for the final artifact.

Fixes rust-lang#156320.
rust-bors Bot pushed a commit that referenced this pull request Jul 8, 2026
Rollup of 25 pull requests

Successful merges:

 - #158871 (add relnotes for 1.97.0)
 - #158968 (stdarch subtree update)
 - #157690 (codegen_ssa: pack small const aggregates into immediate stores)
 - #158541 (Move `std::io::Write` to `core::io`)
 - #154445 (rustdoc: Represent `--output-format=json` coverage and ir differently)
 - #156370 (Reject linked dylib EII default overrides)
 - #157153 (allow `Allocator`s to be used as `#[global_allocator]`s)
 - #158495 (Rename HAS_CT_PROJECTION to HAS_CONST_ALIAS)
 - #158617 (allow mGCA const arguments to fall back to anon consts)
 - #158645 (Fix splat ICEs and ban it in closures)
 - #158655 (Fix coroutine MIR saved local remapping)
 - #158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`)
 - #158870 (std: merge the unix-like io::error modules into one file)
 - #158920 (Update wasm-component-ld to 0.5.26)
 - #158926 (wrapping_sh* methods: clarify underspecified reference)
 - #158927 (add core test run with `-Zforce-intrinsic-fallback`)
 - #158932 (Do not build the compiler when invoking `x perf compare`)
 - #158937 (Emit the emscripten entry point as `__main_argc_argv`)
 - #151379 (Stabilize `VecDeque::retain_back` from `truncate_front`)
 - #156144 (Better docs for PartialEq (includes macro rename))
 - #156548 ( Library support for aarch64-unknown-linux-pauthtest target)
 - #158307 (CI job for parallel frontend ui tests)
 - #158347 (Improve generic parameters handling for #[diagnostic::on_const])
 - #158722 (delegation: do not always inherit `ConstArgHasType` predicates)
 - #158741 (Simplify `Option::into_flat_iter` signature)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-extern_item_impls `#![feature(extern_item_impls)]` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't allow overriding an EII default defined in a dylib

6 participants